package com.recruit.servlet;

import com.recruit.entity.CompanyUser;
import com.recruit.service.UpdateCompanyService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateCompanyServlet",urlPatterns = "/updateCompany")
public class UpdateCompanyServlet extends HttpServlet {
    private UpdateCompanyService updateCompanyService = new UpdateCompanyService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取修改数据
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        String companyName = request.getParameter("companyName");

        //封装CompanyUser
        CompanyUser companyUser = new CompanyUser();
        companyUser.setUsername(username);
        companyUser.setPassword(password);
        companyUser.setEmail(email);
        companyUser.setPhone(phone);
        companyUser.setCompanyName(companyName);
        //调用service
        int i = updateCompanyService.updateCompanyInfo(companyUser);
        if (i>0){
            request.setAttribute("updateCompanyInfo","信息修改成功");
        }else {
            request.setAttribute("updateCompanyInfo","信息修改失败,请联系管理员！");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
